<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
</head>
<body>


    <script>
        // 定义函数 findRepeat，
        // 找出数组中重复的数据,并通过数组返回
        // 如果数组没有重复的数据则返回空数组
        // 例如
      
        function findRepeat(array) {
            for(var i = 0 ; i < array.length ; i ++) {
                var j = i -1 ;
                var temp = array[i];
                if(j >=0 && temp == array[j]) {
                    var res = [];
                    res.push(temp);
                    console.log(res);
                }else{
                    array = array.splice(temp);
                }
            }
            return res;
        }
        findRepeat(arr);

        

        // 例如：
        var arr = ["aaa","red","red","green","aaa"];
        var arr2 = [11,22,33];
        console.log(findRepeat(arr));// ["aaa","red"]
        console.log(findRepeat(arr2));// []

    </script>
</body>
</html>